/*
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
*/
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include "tab0.h"

char * empty_puzzle=".................................................................................";
char * puzstart="12345678945................2.....................................................";

/* tables to speed up the process bit field to list
   first table is the list of bits for each value of a byte
   second table is an index to the first table

*/
int tv_string[1024]={
0,1,0,1,2,0,2,1,2,0,1,2,3,0,3,1,3,0,1,3,2,3,0,2,3,1,2,3,0,1,2,3,
4,0,4,1,4,0,1,4,2,4,0,2,4,1,2,4,0,1,2,4,3,4,0,3,4,1,3,4,0,1,3,4,
2,3,4,0,2,3,4,1,2,3,4,0,1,2,3,4,5,0,5,1,5,0,1,5,2,5,0,2,5,1,2,5,
0,1,2,5,3,5,0,3,5,1,3,5,0,1,3,5,2,3,5,0,2,3,5,1,2,3,5,0,1,2,3,5,
4,5,0,4,5,1,4,5,0,1,4,5,2,4,5,0,2,4,5,1,2,4,5,0,1,2,4,5,3,4,5,0,
3,4,5,1,3,4,5,0,1,3,4,5,2,3,4,5,0,2,3,4,5,1,2,3,4,5,0,1,2,3,4,5,
6,0,6,1,6,0,1,6,2,6,0,2,6,1,2,6,0,1,2,6,3,6,0,3,6,1,3,6,0,1,3,6,
2,3,6,0,2,3,6,1,2,3,6,0,1,2,3,6,4,6,0,4,6,1,4,6,0,1,4,6,2,4,6,0,
2,4,6,1,2,4,6,0,1,2,4,6,3,4,6,0,3,4,6,1,3,4,6,0,1,3,4,6,2,3,4,6,
0,2,3,4,6,1,2,3,4,6,0,1,2,3,4,6,5,6,0,5,6,1,5,6,0,1,5,6,2,5,6,0,
2,5,6,1,2,5,6,0,1,2,5,6,3,5,6,0,3,5,6,1,3,5,6,0,1,3,5,6,2,3,5,6,
0,2,3,5,6,1,2,3,5,6,0,1,2,3,5,6,4,5,6,0,4,5,6,1,4,5,6,0,1,4,5,6,
2,4,5,6,0,2,4,5,6,1,2,4,5,6,0,1,2,4,5,6,3,4,5,6,0,3,4,5,6,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3,5,6,7,0,1,2,3,5,6,7,
4,5,6,7,0,4,5,6,7,1,4,5,6,7,0,1,4,5,6,7,2,4,5,6,7,0,2,4,5,6,7,1,
2,4,5,6,7,0,1,2,4,5,6,7,3,4,5,6,7,0,3,4,5,6,7,1,3,4,5,6,7,0,1,3,
4,5,6,7,2,3,4,5,6,7,0,2,3,4,5,6,7,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
};
int tv_strindex[256]={
0,1,2,4,5,7,9,12,13,15,17,20,22,25,28,32,
33,35,37,40,42,45,48,52,54,57,60,64,67,71,75,80,
81,83,85,88,90,93,96,100,102,105,108,112,115,119,123,128,
130,133,136,140,143,147,151,156,159,163,167,172,176,181,186,192,
193,195,197,200,202,205,208,212,214,217,220,224,227,231,235,240,
242,245,248,252,255,259,263,268,271,275,279,284,288,293,298,304,
306,309,312,316,319,323,327,332,335,339,343,348,352,357,362,368,
371,375,379,384,388,393,398,404,408,413,418,424,429,435,441,448,
449,451,453,456,458,461,464,468,470,473,476,480,483,487,491,496,
498,501,504,508,511,515,519,524,527,531,535,540,544,549,554,560,
562,565,568,572,575,579,583,588,591,595,599,604,608,613,618,624,
627,631,635,640,644,649,654,660,664,669,674,680,685,691,697,704,
706,709,712,716,719,723,727,732,735,739,743,748,752,757,762,768,
771,775,779,784,788,793,798,804,808,813,818,824,829,835,841,848,
851,855,859,864,868,873,878,884,888,893,898,904,909,915,921,928,
932,937,942,948,953,959,965,972,977,983,989,996,1002,1009,1016,1024,
};

char * Blancs(int n,int no)
 {static char wt[]="___________________ ",
              wn[]="                    ";
              if(no)return &wn[20-n]; else return &wt[20-n];}


int  String27(int f,int * r){// copied from bitfields
	if(!f)	return 0;
	word n=0,drb=0;
	unsigned int v=f;
	while(1){ // stop as soon as possible
		int mybyte=v&0xff;
		if(mybyte){
			int il=tv_strindex[mybyte];
			for(int  i=tv_strindex[mybyte-1];i<il;i++){
				r[n++]=tv_string[i]+drb;
			}
		}
		v>>=8;
		if(!v)				break;
		drb+=8;
	}
	return n;
}

void Coutg9(char * zl,int x){
	for(int i=0;i<9;i++){
		cout <<zl[i];
		if(i==2 || i== 5) cout << " ";
	}
	if(x==1) {cout <<endl; return;}
	if(!x) {cout <<"\t"; return;}
}

void CoutGrid(char * zc){
	cout << endl;
	for(int i=0;i<9;i++){
		Coutg9(&zc[9*i],1);
		if(i==2 || i== 5) cout <<endl;
	}
	cout << endl;
}

void PUZ::OutGrid(){
	CoutGrid(gg.puz);
}

int BF3::String(int * r){
	word n=0,drb;
	for(int i=0;i<3;i++){
		int f=bf[i];
		if(!f)	continue;;
		unsigned int v=f;
		drb=27*i;
		while(1){ // stop as soon as possible
			int mybyte=v&0xff;
			if(mybyte){
				int il=tv_strindex[mybyte];
				for(int  i=tv_strindex[mybyte-1];i<il;i++){
					r[n++]=tv_string[i]+drb;
				}
			}
			v>>=8;
			if(!v)				break;
			drb+=8;
		}
	}
	return n;	 
}

char * Char27out(int w){
	static char ws[28];
	strncpy(ws ,empty_puzzle,27);
	ws[27]=0;
	for(int j=26;j>=0;j--) if(w & (1<<j))			ws[j]='1';
	return ws;

}

char * BF3::String(char ws[82]){
	strcpy(ws ,empty_puzzle);
	int w=bf[0];
	for(int j=26;j>=0;j--) if(w & (1<<j))
			ws[j]='1';
	w=bf[1];
	for(int j=26;j>=0;j--) if(w & (1<<j))
		ws[j+27]='1';
	w=bf[2];
	for(int j=26;j>=0;j--) if(w & (1<<j))
		ws[j+54]='1';
	return ws;
}



USHORT BF3::GetRegion(int unit){
	byte *t = cellsInGroup[unit];
	BF9 rr;
	for(int i=0;i<9;i++,t++)
		if(this->On(*t))rr.Set(i);
	return rr.f;
}

BF9 BF3::GetBFRegion(int unit){
	byte *t = cellsInGroup[unit];
	BF9 rr;
	for(int i=0;i<9;i++,t++)
		if(this->On(*t))rr.Set(i);
	return rr;
}

USHORT BF3::CellsUnit(int unit,USHORT *r) {
	USHORT n=0;
	byte *t = cellsInGroup[unit];
	for(int i=0;i<9;i++,t++)
		if(this->On(*t)) r[n++]=*t;
	return n;
}


void SortBF3Table(BF3 * t,int n){
	// this is for short tables or for debugging purpose
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(t[i]>t[j]){
				BF3 temp=t[i];
				t[i]=t[j];
				t[j]=temp;
			}
		}
	}
}

void CleanSortBF3Table(BF3 * t,int n){
	// this is for short tables or for debugging purpose
	SortBF3Table(t,n);
	int nn=0;
	for(int i=1;i<n;i++) if(!(t[i]>t[nn])){
		nn++;
		if(nn<i)t[nn]=t[i];
	}
	n=nn+1;

}

void CoutBF3Table(BF3 * t,int n){
	char ws[82]; ws[81]=0;
	for(int i=1;i<n;i++) 
		cout << t[i].String(ws)<<endl;
}

BF3 AndTable(BF3 * t,int n){
	BF3 w=bf3_all1;
	for(int i=0;i<n;i++) w &= t[i];
	return w;	
}

USHORT BF9::String(USHORT * r){ // same as BF32 mas 2 bytes active
	if(!f)	return 0;
	USHORT n=0,drb=0;
	word v=f;
	while(1){ // stop as soon as possible
		int mybyte=v&0xff;
		if(mybyte){
			int il=tv_strindex[mybyte];
			for(int  i=tv_strindex[mybyte-1];i<il;i++){
				r[n++]=tv_string[i]+drb;
			}
		}
		v>>=8;
		if(!v)				break;
		drb+=8;
	}
	return n;	
}


int C_FIX::GetTableRegions(USHORT * tt,C_FIX & cell2){
	int n=0;
	if(el==cell2.el) tt[n++]=el;
	if(pl==cell2.pl) tt[n++]=plu;
	if(eb==cell2.eb) tt[n++]=ebu;
	return n;
}

BF3 bf3_all0={0,0,0},bf3_all1={0777777777,0777777777,0777777777};

BF3 B3_unit[27]={
	{0777,0,0},{0777000,0,0},{0777000000,0,0},
	{0,0777,0},{0,0777000,0},{0,0777000000,0},
	{0,0,0777},{0,0,0777000},{0,0,0777000000},  // rows
	{01001001,01001001,01001001},{02002002,02002002,02002002},{04004004,04004004,04004004},
	{010010010,010010010,010010010},{020020020,020020020,020020020},{040040040,040040040,040040040},
	{0100100100,0100100100,0100100100},{0200200200,0200200200,0200200200},{0400400400,0400400400,0400400400},
	{07007007,0,0},	{070070070,0,0},	{0700700700,0,0},
	{0,07007007,0},	{0,070070070,0},	{0,0700700700,0},
	{0,0,07007007},	{0,0,070070070},	{0,0,0700700700},
};

BF3 *bf3boxes=&B3_unit[18];


int BitCount[512]={// number of bits in a 9 bits value
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,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0,1,0,3,0,1,0,2,0,1,0,
5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
};

int Tbllook[256]={
	0,1,2,2,4,4,4,4,8,8,8,8,8,8,8,8,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
	32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
	64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
	64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
};

int * TblBitIndex=Tblfirst0_8;
//The cell indexes in each of the 9 rows, 9 columns, and 9 squares out of fss
byte cellsInGroup[27][9] =
{
	{ 0, 1, 2, 3, 4, 5, 6, 7, 8},{ 9,10,11,12,13,14,15,16,17},{18,19,20,21,22,23,24,25,26},
	{27,28,29,30,31,32,33,34,35},{36,37,38,39,40,41,42,43,44},{45,46,47,48,49,50,51,52,53},
	{54,55,56,57,58,59,60,61,62},{63,64,65,66,67,68,69,70,71},{72,73,74,75,76,77,78,79,80},
	{ 0, 9,18,27,36,45,54,63,72},{ 1,10,19,28,37,46,55,64,73},{ 2,11,20,29,38,47,56,65,74},
	{ 3,12,21,30,39,48,57,66,75},{ 4,13,22,31,40,49,58,67,76},{ 5,14,23,32,41,50,59,68,77},
	{ 6,15,24,33,42,51,60,69,78},{ 7,16,25,34,43,52,61,70,79},{ 8,17,26,35,44,53,62,71,80},
	{ 0, 1, 2, 9,10,11,18,19,20},{ 3, 4, 5,12,13,14,21,22,23},{ 6, 7, 8,15,16,17,24,25,26},
	{27,28,29,36,37,38,45,46,47},{30,31,32,39,40,41,48,49,50},{33,34,35,42,43,44,51,52,53},
	{54,55,56,63,64,65,72,73,74},{57,58,59,66,67,68,75,76,77},{60,61,62,69,70,71,78,79,80}
};

byte miniline[54][3] =
{	{ 0, 1, 2},{ 3, 4, 5},{ 6, 7, 8},{ 9,10,11},{12,13,14},{15,16,17},{18,19,20},{21,22,23},{24,25,26},
	{27,28,29},{30,31,32},{33,34,35},{36,37,38},{39,40,41},{42,43,44},{45,46,47},{48,49,50},{51,52,53},
	{54,55,56},{57,58,59},{60,61,62},{63,64,65},{66,67,68},{69,70,71},{72,73,74},{75,76,77},{78,79,80},
	{ 0, 9,18},{27,36,45},{54,63,72},{ 1,10,19},{28,37,46},{55,64,73},{ 2,11,20},{29,38,47},{56,65,74},
	{ 3,12,21},{30,39,48},{57,66,75},{ 4,13,22},{31,40,49},{58,67,76},{ 5,14,23},{32,41,50},{59,68,77},
	{ 6,15,24},{33,42,51},{60,69,78},{ 7,16,25},{34,43,52},{61,70,79},{ 8,17,26},{35,44,53},{62,71,80}
};

byte box_miniline[54][3] =
{	{ 0, 1, 2},{ 9,10,11},{18,19,20},{ 0, 9,18},{ 1,10,19},{ 2,11,20},
	{ 3, 4, 5},{12,13,14},{21,22,23},{ 3,12,21},{ 4,13,22},{ 5,14,23},
	{ 6, 7, 8},{15,16,17},{24,25,26},{ 6,15,24},{ 7,16,25},{ 8,17,26},
	{27,28,29},{36,37,38},{45,46,47},{27,36,45},{28,37,46},{29,38,47},
	{30,31,32},{39,40,41},{48,49,50},{30,39,48},{31,40,49},{32,41,50},
	{33,34,35},{42,43,44},{51,52,53},{33,42,51},{34,43,52},{35,44,53},
	{54,55,56},{63,64,65},{72,73,74},{54,63,72},{55,64,73},{56,65,74},
	{57,58,59},{66,67,68},{75,76,77},{57,66,75},{58,67,76},{59,68,77},
	{60,61,62},{69,70,71},{78,79,80},{60,69,78},{61,70,79},{62,71,80}
};

int tperm6[6][3]={0,1,2,0,2,1,1,0,2,// band order
                        1,2,0,2,0,1,2,1,0};  // all perms
int tperm3[3][3]={{0,1,2},{1,2,0},{2,0,1}}; // here all boxes are in pos 1


int TblMult3[9]={0,3,6,9,12,15,18,21,24};  // 3*i
int TblMult9[9]={0,9,18,27,36,45,54,63,72};  // 9*i
int C_minirow[81]={// TblDiv3 as 27 sub table cell to minirow 
0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,
9,9,9,10,10,10,11,11,11,12,12,12,13,13,13,14,14,14,15,15,15,16,16,16,17,17,17,
18,18,18,19,19,19,20,20,20,21,21,21,22,22,22,23,23,23,24,24,24,25,25,25,26,26,26,
};
int * Tbldiv3=C_minirow; //i/3 eg :  mini row or digit in F
int C_row[81]={// cell to row
0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,
};
int * Tblofftorow=C_row;
int C_col[81]={
0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,
0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,
0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,
};
int * TblMod9=C_col; //i%9 eg : column in block or cell to column
int C_box[81]={
0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2,
3,3,3,4,4,4,5,5,5,3,3,3,4,4,4,5,5,5,3,3,3,4,4,4,5,5,5,
6,6,6,7,7,7,8,8,8,6,6,6,7,7,7,8,8,8,6,6,6,7,7,7,8,8,8,
};
int * Tblofftobox=C_box;//(i%9)/3offset to box
int C_box_rel[81]={
0,1,2,0,1,2,0,1,2,3,4,5,3,4,5,3,4,5,6,7,8,6,7,8,6,7,8,
0,1,2,0,1,2,0,1,2,3,4,5,3,4,5,3,4,5,6,7,8,6,7,8,6,7,8,
0,1,2,0,1,2,0,1,2,3,4,5,3,4,5,3,4,5,6,7,8,6,7,8,6,7,8,
};
int * TblCelltoBox=C_box_rel;// relative position in the box
int C_transpose_c[81]={
80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,
};
int C_transpose_d[81]={
0,9,18,27,36,45,54,63,72,1,10,19,28,37,46,55,64,73,2,11,20,29,38,47,56,65,74,3,12,21,30,39,48,57,66,75,4,13,22,31,40,49,58,67,76,5,14,23,32,41,50,59,68,77,6,15,24,33,42,51,60,69,78,7,16,25,34,43,52,61,70,79,8,17,26,35,44,53,62,71,80,
};
int C_transpose_d2[81]={
80,71,62,53,44,35,26,17,8,79,70,61,52,43,34,25,16,7,78,69,60,51,42,33,24,15,6,
77,68,59,50,41,32,23,14,5,76,67,58,49,40,31,22,13,4,75,66,57,48,39,30,21,12,3,
74,65,56,47,38,29,20,11,2,73,64,55,46,37,28,19,10,1,72,63,54,45,36,27,18,9,0,
};
int C_transpose_r[81]={
8,17,26,35,44,53,62,71,80,7,16,25,34,43,52,61,70,79,6,15,24,33,42,51,60,69,78,
5,14,23,32,41,50,59,68,77,4,13,22,31,40,49,58,67,76,3,12,21,30,39,48,57,66,75,
2,11,20,29,38,47,56,65,74,1,10,19,28,37,46,55,64,73,0,9,18,27,36,45,54,63,72,
};

int  box_col_to_row[512]={// transpose a box
00,01,010,011,0100,0101,0110,0111,02,03,012,013,0102,0103,0112,0113,
020,021,030,031,0120,0121,0130,0131,022,023,032,033,0122,0123,0132,0133,
0200,0201,0210,0211,0300,0301,0310,0311,0202,0203,0212,0213,0302,0303,0312,0313,
0220,0221,0230,0231,0320,0321,0330,0331,0222,0223,0232,0233,0322,0323,0332,0333,
04,05,014,015,0104,0105,0114,0115,06,07,016,017,0106,0107,0116,0117,
024,025,034,035,0124,0125,0134,0135,026,027,036,037,0126,0127,0136,0137,
0204,0205,0214,0215,0304,0305,0314,0315,0206,0207,0216,0217,0306,0307,0316,0317,
0224,0225,0234,0235,0324,0325,0334,0335,0226,0227,0236,0237,0326,0327,0336,0337,
040,041,050,051,0140,0141,0150,0151,042,043,052,053,0142,0143,0152,0153,
060,061,070,071,0160,0161,0170,0171,062,063,072,073,0162,0163,0172,0173,
0240,0241,0250,0251,0340,0341,0350,0351,0242,0243,0252,0253,0342,0343,0352,0353,
0260,0261,0270,0271,0360,0361,0370,0371,0262,0263,0272,0273,0362,0363,0372,0373,
044,045,054,055,0144,0145,0154,0155,046,047,056,057,0146,0147,0156,0157,
064,065,074,075,0164,0165,0174,0175,066,067,076,077,0166,0167,0176,0177,
0244,0245,0254,0255,0344,0345,0354,0355,0246,0247,0256,0257,0346,0347,0356,0357,
0264,0265,0274,0275,0364,0365,0374,0375,0266,0267,0276,0277,0366,0367,0376,0377,
0400,0401,0410,0411,0500,0501,0510,0511,0402,0403,0412,0413,0502,0503,0512,0513,
0420,0421,0430,0431,0520,0521,0530,0531,0422,0423,0432,0433,0522,0523,0532,0533,
0600,0601,0610,0611,0700,0701,0710,0711,0602,0603,0612,0613,0702,0703,0712,0713,
0620,0621,0630,0631,0720,0721,0730,0731,0622,0623,0632,0633,0722,0723,0732,0733,
0404,0405,0414,0415,0504,0505,0514,0515,0406,0407,0416,0417,0506,0507,0516,0517,
0424,0425,0434,0435,0524,0525,0534,0535,0426,0427,0436,0437,0526,0527,0536,0537,
0604,0605,0614,0615,0704,0705,0714,0715,0606,0607,0616,0617,0706,0707,0716,0717,
0624,0625,0634,0635,0724,0725,0734,0735,0626,0627,0636,0637,0726,0727,0736,0737,
0440,0441,0450,0451,0540,0541,0550,0551,0442,0443,0452,0453,0542,0543,0552,0553,
0460,0461,0470,0471,0560,0561,0570,0571,0462,0463,0472,0473,0562,0563,0572,0573,
0640,0641,0650,0651,0740,0741,0750,0751,0642,0643,0652,0653,0742,0743,0752,0753,
0660,0661,0670,0671,0760,0761,0770,0771,0662,0663,0672,0673,0762,0763,0772,0773,
0444,0445,0454,0455,0544,0545,0554,0555,0446,0447,0456,0457,0546,0547,0556,0557,
0464,0465,0474,0475,0564,0565,0574,0575,0466,0467,0476,0477,0566,0567,0576,0577,
0644,0645,0654,0655,0744,0745,0754,0755,0646,0647,0656,0657,0746,0747,0756,0757,
0664,0665,0674,0675,0764,0765,0774,0775,0666,0667,0676,0677,0766,0767,0776,0777,
};
int C_mod27[81]={
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,
};
int * Tbloffset=C_mod27; // giving cell to offset in a band
int C_div27[81]={
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
};
int * TblBoard_Block=C_div27; // giving cell -> band 

C_FIX C_fix[81]={
{ 0,0,0,9,0,18,0,"r1c1",{07007776,01001001,01001001}},
{ 1,0,1,10,0,18,1,"r1c2",{07007775,02002002,02002002}},
{ 2,0,2,11,0,18,2,"r1c3",{07007773,04004004,04004004}},
{ 3,0,3,12,1,19,0,"r1c4",{070070767,010010010,010010010}},
{ 4,0,4,13,1,19,1,"r1c5",{070070757,020020020,020020020}},
{ 5,0,5,14,1,19,2,"r1c6",{070070737,040040040,040040040}},
{ 6,0,6,15,2,20,0,"r1c7",{0700700677,0100100100,0100100100}},
{ 7,0,7,16,2,20,1,"r1c8",{0700700577,0200200200,0200200200}},
{ 8,0,8,17,2,20,2,"r1c9",{0700700377,0400400400,0400400400}},
{ 9,1,0,9,0,18,3,"r2c1",{07776007,01001001,01001001}},
{ 10,1,1,10,0,18,4,"r2c2",{07775007,02002002,02002002}},
{ 11,1,2,11,0,18,5,"r2c3",{07773007,04004004,04004004}},
{ 12,1,3,12,1,19,3,"r2c4",{070767070,010010010,010010010}},
{ 13,1,4,13,1,19,4,"r2c5",{070757070,020020020,020020020}},
{ 14,1,5,14,1,19,5,"r2c6",{070737070,040040040,040040040}},
{ 15,1,6,15,2,20,3,"r2c7",{0700677700,0100100100,0100100100}},
{ 16,1,7,16,2,20,4,"r2c8",{0700577700,0200200200,0200200200}},
{ 17,1,8,17,2,20,5,"r2c9",{0700377700,0400400400,0400400400}},
{ 18,2,0,9,0,18,6,"r3c1",{0776007007,01001001,01001001}},
{ 19,2,1,10,0,18,7,"r3c2",{0775007007,02002002,02002002}},
{ 20,2,2,11,0,18,8,"r3c3",{0773007007,04004004,04004004}},
{ 21,2,3,12,1,19,6,"r3c4",{0767070070,010010010,010010010}},
{ 22,2,4,13,1,19,7,"r3c5",{0757070070,020020020,020020020}},
{ 23,2,5,14,1,19,8,"r3c6",{0737070070,040040040,040040040}},
{ 24,2,6,15,2,20,6,"r3c7",{0677700700,0100100100,0100100100}},
{ 25,2,7,16,2,20,7,"r3c8",{0577700700,0200200200,0200200200}},
{ 26,2,8,17,2,20,8,"r3c9",{0377700700,0400400400,0400400400}},
{ 27,3,0,9,3,21,0,"r4c1",{01001001,07007776,01001001}},
{ 28,3,1,10,3,21,1,"r4c2",{02002002,07007775,02002002}},
{ 29,3,2,11,3,21,2,"r4c3",{04004004,07007773,04004004}},
{ 30,3,3,12,4,22,0,"r4c4",{010010010,070070767,010010010}},
{ 31,3,4,13,4,22,1,"r4c5",{020020020,070070757,020020020}},
{ 32,3,5,14,4,22,2,"r4c6",{040040040,070070737,040040040}},
{ 33,3,6,15,5,23,0,"r4c7",{0100100100,0700700677,0100100100}},
{ 34,3,7,16,5,23,1,"r4c8",{0200200200,0700700577,0200200200}},
{ 35,3,8,17,5,23,2,"r4c9",{0400400400,0700700377,0400400400}},
{ 36,4,0,9,3,21,3,"r5c1",{01001001,07776007,01001001}},
{ 37,4,1,10,3,21,4,"r5c2",{02002002,07775007,02002002}},
{ 38,4,2,11,3,21,5,"r5c3",{04004004,07773007,04004004}},
{ 39,4,3,12,4,22,3,"r5c4",{010010010,070767070,010010010}},
{ 40,4,4,13,4,22,4,"r5c5",{020020020,070757070,020020020}},
{ 41,4,5,14,4,22,5,"r5c6",{040040040,070737070,040040040}},
{ 42,4,6,15,5,23,3,"r5c7",{0100100100,0700677700,0100100100}},
{ 43,4,7,16,5,23,4,"r5c8",{0200200200,0700577700,0200200200}},
{ 44,4,8,17,5,23,5,"r5c9",{0400400400,0700377700,0400400400}},
{ 45,5,0,9,3,21,6,"r6c1",{01001001,0776007007,01001001}},
{ 46,5,1,10,3,21,7,"r6c2",{02002002,0775007007,02002002}},
{ 47,5,2,11,3,21,8,"r6c3",{04004004,0773007007,04004004}},
{ 48,5,3,12,4,22,6,"r6c4",{010010010,0767070070,010010010}},
{ 49,5,4,13,4,22,7,"r6c5",{020020020,0757070070,020020020}},
{ 50,5,5,14,4,22,8,"r6c6",{040040040,0737070070,040040040}},
{ 51,5,6,15,5,23,6,"r6c7",{0100100100,0677700700,0100100100}},
{ 52,5,7,16,5,23,7,"r6c8",{0200200200,0577700700,0200200200}},
{ 53,5,8,17,5,23,8,"r6c9",{0400400400,0377700700,0400400400}},
{ 54,6,0,9,6,24,0,"r7c1",{01001001,01001001,07007776}},
{ 55,6,1,10,6,24,1,"r7c2",{02002002,02002002,07007775}},
{ 56,6,2,11,6,24,2,"r7c3",{04004004,04004004,07007773}},
{ 57,6,3,12,7,25,0,"r7c4",{010010010,010010010,070070767}},
{ 58,6,4,13,7,25,1,"r7c5",{020020020,020020020,070070757}},
{ 59,6,5,14,7,25,2,"r7c6",{040040040,040040040,070070737}},
{ 60,6,6,15,8,26,0,"r7c7",{0100100100,0100100100,0700700677}},
{ 61,6,7,16,8,26,1,"r7c8",{0200200200,0200200200,0700700577}},
{ 62,6,8,17,8,26,2,"r7c9",{0400400400,0400400400,0700700377}},
{ 63,7,0,9,6,24,3,"r8c1",{01001001,01001001,07776007}},
{ 64,7,1,10,6,24,4,"r8c2",{02002002,02002002,07775007}},
{ 65,7,2,11,6,24,5,"r8c3",{04004004,04004004,07773007}},
{ 66,7,3,12,7,25,3,"r8c4",{010010010,010010010,070767070}},
{ 67,7,4,13,7,25,4,"r8c5",{020020020,020020020,070757070}},
{ 68,7,5,14,7,25,5,"r8c6",{040040040,040040040,070737070}},
{ 69,7,6,15,8,26,3,"r8c7",{0100100100,0100100100,0700677700}},
{ 70,7,7,16,8,26,4,"r8c8",{0200200200,0200200200,0700577700}},
{ 71,7,8,17,8,26,5,"r8c9",{0400400400,0400400400,0700377700}},
{ 72,8,0,9,6,24,6,"r9c1",{01001001,01001001,0776007007}},
{ 73,8,1,10,6,24,7,"r9c2",{02002002,02002002,0775007007}},
{ 74,8,2,11,6,24,8,"r9c3",{04004004,04004004,0773007007}},
{ 75,8,3,12,7,25,6,"r9c4",{010010010,010010010,0767070070}},
{ 76,8,4,13,7,25,7,"r9c5",{020020020,020020020,0757070070}},
{ 77,8,5,14,7,25,8,"r9c6",{040040040,040040040,0737070070}},
{ 78,8,6,15,8,26,6,"r9c7",{0100100100,0100100100,0677700700}},
{ 79,8,7,16,8,26,7,"r9c8",{0200200200,0200200200,0577700700}},
{ 80,8,8,17,8,26,8,"r9c9",{0400400400,0400400400,0377700700}},
};
CELL_UX cell_u[81];

#include "tab0b.cpp"